package com.smart.home.command;

import com.smart.home.button.WirelessButton;
import com.smart.home.command.common.BaseCommand;
import com.smart.home.netty.NettyUtils;
import com.smart.home.netty.handler.AbstractChannelInboundHandler;
import com.smart.home.netty.handler.WirelessExecuteCommandHandler;

/**
 * 无线控制
 *
 * @author zhangpeng
 * @version 1.0
 * @date 2017-03-10
 */
public class WirelessCommand extends BaseCommand {

    public WirelessCommand(String deviceCode, String host, int port) {
        super(deviceCode, host, port);
    }

    public boolean execute(WirelessButton button){
        if (button == null){
            return false;
        }
        String command = getDeviceCode() + button.getExecuteCode();
        WirelessExecuteCommandHandler handler = new WirelessExecuteCommandHandler(command);
        AbstractChannelInboundHandler result = NettyUtils.sendCommand(handler, getHost(), getPort());
        return result.isStatus();
    }

}
